package com.codedancer.campus.manager.api.confessionalWall;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.codedancer.campus.common.anno.InterfacePermission;
import com.codedancer.campus.common.core.BaseApi;
import com.codedancer.campus.common.response.ApiResponse;
import com.codedancer.campus.manager.api.commodity.ro.CommodityExamineRo;
import com.codedancer.campus.manager.api.confessionalWall.ro.ConfessionalWallPageSearchRo;
import com.codedancer.campus.manager.api.confessionalWall.ro.ConfessionalWallRo;
import com.codedancer.campus.manager.service.IConfessionalWallService;
import com.codedancer.campus.manager.service.bo.commodity.CommodityExamineBo;
import com.codedancer.campus.manager.service.bo.confessionalWall.ConfessionalWallBo;
import com.codedancer.campus.manager.service.bo.confessionalWall.ConfessionalWallPageSearchBo;
import com.codedancer.campus.manager.service.vo.confessionalWall.ConfessionalWallPageVo;
import com.codedancer.campus.manager.service.vo.confessionalWall.ConfessionalWallVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/confessional-wall")
@CrossOrigin(methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE,
    RequestMethod.PUT}, maxAge = 3600)
@Api(value = "表白墙Api", description = "表白墙Api", tags = "表白墙Api")
public class ConfessionalWallApi extends BaseApi {

    @Autowired
    private IConfessionalWallService confessionalWallService;

    @GetMapping("/page")
    @ApiOperation("分页查询表白墙")
    @InterfacePermission(encodes = {"superAdmin","confessionalWallAdmin"})
    public ApiResponse<IPage<ConfessionalWallPageVo>> page(
        @ApiParam(value = "表白墙分页查询Ro", required = false)
            ConfessionalWallPageSearchRo confessionalWallPageSearchRo) {
        ConfessionalWallPageSearchBo confessionalWallPageSearchBo = BeanUtil
            .copyProperties(confessionalWallPageSearchRo, ConfessionalWallPageSearchBo.class);
        return success(confessionalWallService.page(confessionalWallPageSearchBo));
    }

    @DeleteMapping("/delete/{uuid}")
    @ApiOperation("删除表白墙")
    @InterfacePermission(encodes = {"superAdmin","confessionalWallAdmin"})
    public ApiResponse<Void> delete(
        @PathVariable(value = "uuid", required = true) @ApiParam(value = "商品uuid", required = true) String uuid) {
        confessionalWallService.delete(uuid);
        return success();
    }

    @PostMapping("/export")
    @ApiOperation("导出表白墙")
    @InterfacePermission(encodes = {"superAdmin","confessionalWallAdmin"})
    public void export(HttpServletRequest request, HttpServletResponse response,
        @ApiParam(value = "表白墙分页查询Ro", required = false)
            ConfessionalWallPageSearchRo confessionalWallPageSearchRo) {
        ConfessionalWallPageSearchBo confessionalWallPageSearchBo = BeanUtil
            .copyProperties(confessionalWallPageSearchRo, ConfessionalWallPageSearchBo.class);
        confessionalWallService.export(request, response, confessionalWallPageSearchBo);
    }

    @GetMapping("/detail/{uuid}")
    @ApiOperation("表白墙详情")
    @InterfacePermission(encodes = {"superAdmin","confessionalWallAdmin"})
    public ApiResponse<ConfessionalWallVo> detail(
        @PathVariable(value = "uuid", required = true) @ApiParam(value = "表白墙uuid", required = true) String uuid) {
        return success(confessionalWallService.detail(uuid));
    }

    @PutMapping("/no-pass/{uuid}")
    @ApiOperation("审核未通过")
    @InterfacePermission(encodes = {"superAdmin","confessionalWallAdmin"})
    public ApiResponse<Void> noPass(
            @PathVariable(value = "uuid", required = true) @ApiParam(value = "表白墙uuid", required = true) String uuid,
            @RequestBody @ApiParam(value = "表白墙审核Ro", required = true) ConfessionalWallRo confessionalWallRo) {
        ConfessionalWallBo confessionalWallBo = BeanUtil
                .copyProperties(confessionalWallRo, ConfessionalWallBo.class);
        confessionalWallBo.setCurrentUserUuid(currentLoginUuid());
        confessionalWallBo.setUuid(uuid);
        confessionalWallService.noPass(confessionalWallBo);
        return success();
    }

    @PutMapping("/pass/{uuid}")
    @ApiOperation("审核通过")
    @InterfacePermission(encodes = {"superAdmin","confessionalWallAdmin"})
    public ApiResponse<Void> pass(
            @PathVariable(value = "uuid", required = true) @ApiParam(value = "表白墙uuid", required = true) String uuid,
            @RequestBody @ApiParam(value = "表白墙审核Ro", required = true) ConfessionalWallRo confessionalWallRo) {
        ConfessionalWallBo confessionalWallBo = BeanUtil
                .copyProperties(confessionalWallRo, ConfessionalWallBo.class);
        confessionalWallBo.setCurrentUserUuid(currentLoginUuid());
        confessionalWallBo.setUuid(uuid);
        confessionalWallService.pass(confessionalWallBo);
        return success();
    }
}
